package 笔试2.美团.three;


import java.util.*;

/*
6 9
6 7 3 4 9 6
 */
//--最高的相同高度，有魔法使用次数限制
public class Main {

    public static void main(String[] args) {
        int N=6,can=9;
        int[] p = {6,7,3,4,9,6};
        Scanner sc = new Scanner(System.in);
        N=sc.nextInt();
        can= sc.nextInt();
        p =new int[N];
        for (int i = 0; i < N; i++) {
            p[i]=sc.nextInt();
        }

        //--倒序数组
        List<Integer> l = new ArrayList<>();
        for (int i : p) {
            l.add(i);
        }
        Collections.sort(l, (a,b)->b-a);
        for (int i = 0; i < p.length; i++) {
            p[i]=l.get(i);
        }

        //解题
        for (int i = 0; i < p.length; i++) {
            int hav=can; int curMaxH=p[i];
            int fl=0;
            for (int j = i+1; j < p.length; j++) {
                if(p[j]>=p[i])continue;
                else{
                    hav-=(p[i]-p[j]);
//                    System.out.println(hav);
                    if(hav<0 && i<p.length-1 && p[i+1]>0){
                      fl=1;
                      break;
                    }
                }
            }
//            System.out.println("-");
            if(fl==0){
                System.out.println(p[i]);
                return;
            }
        }
    }
}
